package com.yupi.springbootinit.es.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.dromara.easyes.annotation.HighLight;
import org.dromara.easyes.annotation.IndexField;
import org.dromara.easyes.annotation.rely.FieldType;

import java.util.Map;

@Data
@AllArgsConstructor
public  class Message {
    @IndexField(fieldType = FieldType.KEYWORD)
    private String role;
    @IndexField(fieldType = FieldType.TEXT)
    @HighLight(preTag = "<strong>", postTag = "</strong>", numberOfFragments = 15)
    private String content;

    public Message() {

    }

    public static Message fromMap(Map<String, Object> sourceMap) {
        Message message = new Message();
        message.setRole((String) sourceMap.getOrDefault("role", ""));
        message.setContent((String) sourceMap.getOrDefault("content", ""));
        return message;
    }

}